package com.help10000.rms.mvp.presenter

import com.amir.common.api.CustomObserver
import com.amir.common.beans.BaseResult
import com.amir.common.mvp.model.Model
import com.amir.common.utils.Constant
import com.amir.common.utils.SPUtils
import com.amir.common.utils.ToastUtil
import com.help10000.rms.mvp.view.ForgetPwdView

/**
 * @Author: amir
 * @Date: 2021/7/24 3:23 下午
 */
class ForgetPwdPresenter(view: ForgetPwdView) : SMSPresenter(view) {


    override fun getMvpView(): ForgetPwdView {
        return super.getMvpView() as ForgetPwdView
    }

    fun forgetPwd(phone: String, pwd: String, affpwd: String, verifyCode: String) {
        if (pwd.isBlank()) {
            ToastUtil.show("密码不能为空")
            return;
        }
        if (affpwd.isBlank()) {
            ToastUtil.show("确认密码不能为空")
            return;
        }
        if (affpwd != pwd) {
            ToastUtil.show("两次密码不一致，请重新输入")
            return;
        }
        val smsId = SPUtils.getString(Constant.SmsId)
        val forgetPwd = Model.getServer().resetPwd(phone, affpwd, smsId!!, verifyCode)
        Model.getObservable(forgetPwd, object : CustomObserver<BaseResult>(mvpView) {
            override fun success(t: BaseResult) {
                mvpView?.changeSucc();
            }
        })
    }
}
